﻿using DDDNorthWind.Core.Domain.ValueObject;

namespace DDDNorthWind.AC.ImportProducts.Domain.ValueObjects
{
    public class ImportProduct : ValueObject<ImportProduct>
    {
        public ImportProduct()
        {
            Weight = new ImportProductWeight();
            Size = new ImportProductSize();
            LastPrice = new ImportProductPrice();
        }

        public string SKU { get; set; }

        public string Name { get; set; }

        public int? QuantityPerUnit { get; set; }

        public string CategoryId { get; set; }

        public ImportProductWeight Weight {get; private set;}

        public ImportProductSize Size { get; private set; }

        public ImportProductPrice LastPrice { get; private set; }

        public void AssignWeight(string weight, string weightIn)
        {
            //TODO conversion de los dos parametros
            var newImportProductWeight = new ImportProductWeight();

            Weight.UpdateValues(newImportProductWeight);
        }

        #region "Equals"

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override bool Equals(ImportProduct other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other.SKU, SKU)
                && Equals(other.Name, Name)
                && other.QuantityPerUnit.Equals(QuantityPerUnit)
                && Equals(other.CategoryId, CategoryId)
                && Equals(other.Weight, Weight)
                && Equals(other.Size, Size)
                && Equals(other.LastPrice, LastPrice);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = (SKU != null ? SKU.GetHashCode() : 0);
                result = (result * 397) ^ (Name != null ? Name.GetHashCode() : 0);
                result = (result * 397) ^ (QuantityPerUnit.HasValue ? QuantityPerUnit.Value : 0);
                result = (result * 397) ^ (CategoryId != null ? CategoryId.GetHashCode() : 0);
                result = (result * 397) ^ (Weight != null ? Weight.GetHashCode() : 0);
                result = (result * 397) ^ (Size != null ? Size.GetHashCode() : 0);
                result = (result * 397) ^ (LastPrice != null ? LastPrice.GetHashCode() : 0);
                return result;
            }
        }

        public static bool operator ==(ImportProduct left, ImportProduct right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(ImportProduct left, ImportProduct right)
        {
            return !Equals(left, right);
        } 
        #endregion
    }
}